{extend name="public:body" /}

{block name="header"}
  <div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title" style="padding:10px 0;height:30px;">
      <li>桌子列表</li>
    </ul>
  </div>
{/block}
{block name="body"}
  {include file="finance:publics" /}
  <div class="layui-card-body">
    <div class="layui-form search-form">
      <div class="layui-form-item">
        <div class="layui-input-inline">
          <input placeholder="请输入桌子ID号搜索" value="{$param.id}" name="id" type="text" autocomplete="off" class="layui-input">
        </div>        
        <button type="button" onclick="formsearch()" class="layui-btn" autocomplete="off">搜索</button>
        <button type="button" class="layui-btn fright" id="down-menu-btn" onclick="deleted()">一键删除</button>
        
      </div>
    </div>
    
    <table class="layui-table table table-hover table-bordered table-list" id="menus-table" lay-size="sm">
      <thead>
        <tr>
          <th type="normal" width="40" class="tc">
            <input name="th-checkbox" type="checkbox" onchange="checkall()">
          </th>
          <th class="tc">桌子ID</th>
          <th class="tc">房间ID</th>
          <th class="tc">用户ID</th>
          <th class="tc">房间名称</th>
          <th class="tc">用户昵称</th>
          <th class="tc">用户电话</th>          
          <th class="tc">进入最低筹码</th>
          <th class="tc">是否发送文字</th>
          <th class="tc">是否发送语音</th>
          <th class="tc">游戏低分筹码</th>
          <th class="tc">游戏局数</th>
          <th class="tc" width="100">申请时间</th>
          <th class="tc" width="100">审核时间</th>

          <th class="tc" width="70">操作</th>
        </tr>
      </thead>
      <tbody>
        <?php foreach($list as $v){?>
          <tr>
            <td class="tc">
              <input value="{$v.id}" class="tr-checkbox" type="checkbox">
            </td>
            <td class="tc" style="color: #009688">{$v.id}</td>
            <td class="tc" style="color: #1E9FFF">{$v.rid}</td>
            <td class="tc" style="color: #5FB878">{$v.uid}</td>
            <td class="tc" style="color: #FF5722">{$v.name}</td>
            <td class="tc">{$v.username}</td>
            <td class="tc">{$v.phone}</td>
            <td class="tc">{$v.min_balance}</td>           
            <td class="tc">
            {if $v.is_send_text == 1} 是
            {else /} 否
            {/if}
            </td>
            <td class="tc">
            {if $v.is_send_text == 1} 是
            {else /} 否
            {/if}
            </td>
            <td class="tc">{$v.low_grade}</td>
            <td class="tc">{$v.innings}</td>
            <td class="tc">{$v.create_time}</td>
            <td class="tc">{$v.update_time}</td>
            <td class="tc">
              <a class="a-post layui-btn layui-btn-xs layui-btn-danger" style="cursor: pointer;" post-msg="删除数据不可恢复，确认删除吗？" post-url="<?php echo url('delete', ['id'=>$v['id']])?>">删除</a>
            </td>
          </tr>
        <?php } ?>
      </tbody>
      <tfoot>
        <tr>
          <td colspan="15" class="tc">
            {$page|raw}
            <span>共{$count}条</span>
            <span>
              {$limit|raw}
            </span>
          </td>
        </tr>
      </tfoot>
    </table>
  </div>

  <script>
    var url   = "{:url('table/index')}",
        gParam = {
          'page': "{$param.page}",
          'limit': "{$param.limit}",
        }

    // 搜索
    var formsearch = function() {
      var form  = $('.search-form [name]')
      form.each(function(index, ele) {
        var key = $(form[index]).attr('name')
        gParam[key] = $(this).val()
      })

      gParam['page'] = 1
      window.location.href = url + _671.paramFormat(gParam)
    }

    // 页面选择
    var selectlimit = function() {
      gParam['limit'] = $('[name=limit]').val()
      window.location.href = url + _671.paramFormat(gParam)
    }

    // 全选
    var checkall = function() {
      var th = $('[name=th-checkbox]')[0].checked
      $('.tr-checkbox').each(function (index) {
          $('.tr-checkbox')[index].checked = th
      })
    }

    // 选项框操作
    $('.tr-checkbox').change(function() {
      var thchecked = false
      $('.tr-checkbox').each(function(index) {
        var checked = $('.tr-checkbox')[index].checked
        if (checked) {
          thchecked = true
          return ;
        }
      })
      $('[name=th-checkbox]')[0].checked = thchecked
    })

    // 设置选项id
    var getId = function() {
      var idString = ''
      $('.tr-checkbox').each(function(index) {
        var ele = $('.tr-checkbox')[index]
        if (ele.checked) {
          idString += $(ele).attr('value') + ','
        }
      })
      idString = idString.substring(0, idString.length-1)
      return idString
    }

    // 删除
    var deleted = function() {
      layer.confirm('删除数据不可恢复，确认删除吗？', {icon: 3, title:'提示'}, function(index){
        var d = { id: getId() }
        _671.post("{:url('delete')}", d, function(res) {
          if (res.code === 200) {
            layer.msg(res.msg, { icon: 6, time: 1500 }, function() {
              window.location.reload()
            })
          } else {
            layer.msg(res.msg, { icon: 5, time: 1500 })
          }
        })
        layer.close(index)
      })
    }
  </script>
{/block}
